<template>
  <div class="teacherNav">
    <div class="container">
      <router-link
        :to="{ name: item.name }"
        v-for="(item, index) in routes"
        :key="index"
      >
        <div class="flexBox" :class="{ rightBox: index !== 0 }">
          <div>
            <img :src="require('@/assets/images/teachingIcon.png')" v-if="item.name === 'Teaching'" alt="" />
            <img :src="require('@/assets/images/taughtIcon.png')" v-if="item.name === 'Taught'" alt="" />
          </div>
          <div class="title" :class="{ isActive: $route.name == item.name }">
            {{ item.meta.name }}
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  computed: {
    routes() {
      const router = this.$router;
      let newRoutes = router.options.routes.filter(
        (item) => item.name === router.currentRoute.matched[0].name
      )[0].children;
      newRoutes.length = 2;
      return newRoutes;
    },
  },
};
</script>

<style lang="stylus">
.teacherNav {
  height: 84px;
  background-color: #ffffff;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.06);

  .container {
    padding: 0 0 10px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    max-width: 1200px;
    height: 100%;

    .flexBox {
      display: flex;
      align-items: center;
      height: 27px;

      .title {
        margin-left: 5px;
        font-family: PMingLiU-ExtB;
        font-size: 16px;
        color: #003262;
      }

      .isActive {
        position: relative;
        font-weight: bold;
      }

      .isActive::after {
        position: absolute;
        content: '';
        left: 50%;
        right: 50%;
        bottom: -5px;
        width: 60px;
        height: 2px;
        background: #003262;
        transform: translate(-50%, 0);
      }
    }

    .rightBox {
      margin-left: 205px;
    }
  }
}
</style>